package com.yanqu.road.dao.impl.log;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogWinterLoveConvertReward;
import com.yanqu.road.entity.log.LogWinterLoveDig;
import com.yanqu.road.entity.log.LogWinterLovePickUpItem;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogActivityWinterLoveDaoImpl extends TempDao {
    public boolean addLogWinterLovePickUpItemList(List<LogWinterLovePickUpItem> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_winter_love_pick_up_item(userId,activityId,digLevel,turn,itemId,reward,oldBlessing,gainBlessing,newBlessing,time) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogWinterLovePickUpItem data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDigLevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getTurn()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getItemId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldBlessing()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGainBlessing()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewBlessing()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogWinterLoveDigList(List<LogWinterLoveDig> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_winter_love_dig(userId,activityId,digLevel,turn,kickAnimal,digGridNum,oldScore,digScore,newScore,time) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogWinterLoveDig data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDigLevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getTurn()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getKickAnimal()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getDigGridNum())));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldScore()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDigScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewScore()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogWinterLoveConvertRewardList(List<LogWinterLoveConvertReward> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_winter_love_convert_reward(userId,activityId,combId,reward,time) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogWinterLoveConvertReward data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCombId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


}
